#/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2022/1/11 10:05
# @Author  : wf
# @Email   : wf@163.com
# @File    : khhome_page.py
# @Software: PyCharm
"""添加客户界面"""
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
url = 'http://192.168.1.30/crm'

#定位用户名输入框
username_locator = (By.NAME, 'name')
#定位密码输入框
password_locator = (By.NAME, 'password')
#定位登录按钮
submit_locator = (By.NAME, 'submit')
#定位客户控件按钮
kehu_locator = (By.LINK_TEXT,'客户')
#定位新建客户按钮
add_kehu_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div > a')
#定位客户名称输入框
kehu_name_locator = (By.ID,'name')
#定位行业输入框
hangye_locator = (By.ID,'industry')
#定位客户来源输入框
kehu_laiyuan_locator = (By.ID,'origin')
#定位公司性质输入框
gongsi_xingzhi_locator = (By.XPATH,'//*[@id="form1"]/table/tbody/tr[4]/td[2]')
#定位公司营业额输入框
yingyee_locator = (By.ID,'annual_revenue')
#定位省级地址
adress_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(5) > td:nth-child(2) > select:nth-child(2)')
#定位城市输入框
city_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(5) > td:nth-child(2) > select:nth-child(3)')
#定位地区输入框
area_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(5) > td:nth-child(2) > select:nth-child(4)')
#定位联系人输入框
lianxi_person_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(8) > td:nth-child(2) > input')
#定位尊称输入框
zuncheng_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(8) > td:nth-child(4) > input')
#定位邮箱输入框
email_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(9) > td:nth-child(2) > input')
#定位职位输入框
zhiwei_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(8) > td:nth-child(4) > input')
#定位QQ输入框
qq_locator = (By.NAME,'con_qq')
#定位手机输入框
moible_locator = (By.NAME,'con_telephone')
#定位备注输入框
beizhu_locator = (By.CSS_SELECTOR,'#form1 > table > tbody > tr:nth-child(10) > td:nth-child(2) > textarea')
#定位员工人数输入框
yuangong_num_locator = (By.ID,'no_of_employees')
#定位描述输入框
description_locator = (By.ID,'description')
#定位保存按钮
baocun_locator = (By.CSS_SELECTOR,'#form1 > table > tfoot > tr > td > input:nth-child(1)')
#定位添加客户成功
succful_locator = (By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')

class Tianjiakehu_Page:
    def __init__(self,driver):
        self.driver=driver
    #点击客户按钮
    def input_kehu(self):
        self.driver.find_element(*kehu_locator).click()
    #点击新建客户
    def input_add_kehu(self):
        self.driver.find_element(*add_kehu_locator).click()
    #输入客户名称
    def input_kehu_name(self,kehu_name):
        self.driver.find_element(*kehu_name_locator).send_keys(kehu_name)
    #输入客户行业
    def input_hangye(self,hangye):
        Select(self.driver.find_element(*hangye_locator)).select_by_visible_text('电子商务')
    #输入客户来源
    def input_kehu_laiyuan(self,kehu_laiyuan):
        Select(self.driver.find_element(*kehu_laiyuan_locator)).select_by_visible_text('电话营销')

    #输入年营业额
    def input_yingyee(self,yingyee):
        Select(self.driver.find_element(*yingyee_locator)).select_by_visible_text(yingyee)
    #输入省级地址
    def input_adress(self,adress):
        Select(self.driver.find_element(*adress_locator)).select_by_visible_text('四川省')
    #输入市级地址
    def input_city(self,city):
        Select(self.driver.find_element(*city_locator)).select_by_visible_text('成都市')
    #输入地区
    def input_area(self,area):
        Select(self.driver.find_element(*area_locator)).select_by_visible_text('锦江区')
    #输入联系人
    def input_lianxi_person(self,lianxi_person):
        self.driver.find_element(*lianxi_person_locator).send_keys(lianxi_person)
    #输入尊称
    def input_zuncheng(self,zuncheng):
        self.driver.find_element(*zuncheng_locator).send_keys(zuncheng)
    #输入邮箱
    def input_email(self,email):
        self.driver.find_element(*email_locator).send_keys(email)
    #输入职位
    def input_zhiwei(self,zhiwei):
        self.driver.find_element(*zhiwei_locator).send_keys(zhiwei)
    #输入QQ
    def input_qq(self,qq):
        self.driver.find_element(*qq_locator).send_keys(qq)
    #输入电话
    def input_moible(self,moible):
        self.driver.find_element(*moible_locator).send_keys(moible)
    #输入备注
    def input_beizhu(self,beizhu):
        self.driver.find_element(*beizhu_locator).send_keys(beizhu)
    #输入员工人数
    def input_yuangong_num(self,yuangong_num):
        Select(self.driver.find_element(*yuangong_num_locator)).select_by_visible_text(yuangong_num)
    #输入描述
    def input_description(self,description):
        self.driver.find_element(*description_locator).send_keys(description)
    #点击保存
    def input_baocun(self):
        self.driver.find_element(*baocun_locator).click()
    def kh_duanyan(self):
        dy_locator=(By.XPATH,'//*[@id="form1"]/table/tbody/tr[4]/td[3]')
        return self.driver.find_element(*dy_locator).text